import { observable, action } from "mobx";
import Taro from '@tarojs/taro'


/**
 * 数据model
 */
class TabbarItem {
    // @observable
    title: string
    icon: string
    disabled: boolean
    dot?: boolean
    info?: string
    tabUrl?: string
    selected: boolean
    alone?: boolean
    onClick?: (item: TabbarItem) => void

}


export class TabbarModel {

    @observable.ref
    items: TabbarItem[]

    @observable
    selected: string

    @observable
    isCatering: boolean

    constructor() {
        this.items = []
        this.selected = '/pages/home/home/index'
    }

    @action
    setSelected(val: string) {
        this.selected = val
    }

    @action
    getItems(isCatering: boolean) {
        this.items = [
            {
                title: '首页',
                icon: 'home1',
                dot: false,
                disabled: false,
                selected: true,
                tabUrl: '/pages/home/home/index'
            },
            {
                title: isCatering ? '菜单' : '商品',
                icon: 'all',
                dot: false,
                disabled: false,
                // alone: true,
                selected: false,
                tabUrl: '/pages/goods/entry/index',
                onClick: (item: TabbarItem) => {
                    // Taro.scanCode({}).then(()=>{
                    if (item.tabUrl) {
                        Taro.navigateTo({
                            url: item.tabUrl
                        })
                    }
                    // })
            
                }
            },
            {
                title: '订单',
                icon: 'rejected-order',
                disabled: false,
                selected: false,
                dot: false,
                tabUrl: '/pages/center/orders/index'
            },
            {
                title: '我的',
                icon: 'account',
                disabled: false,
                selected: false,
                dot: true,
                tabUrl: '/pages/me/me/index'
            }
        ]


    }
}

export const tabbarModel = new TabbarModel()
